﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using UMLDesigner.Widgets;

namespace UMLDesigner.Widgets
{
    public class AssociateLinkWidget : LinkWidget
    {
        public AssociateLinkWidget()
        {
            InitDefaultSlots();
        }


        public override void DrawItem(Graphics g)
        {
            Option option = CurrentOption.Instance.Option;
            Color outlineColor = option.LineColor;

            GraphicsPath linePath = new GraphicsPath();
            linePath.AddLine(SourceSlot.Location, DestinationSlot.Location);

            GraphicsPath hPath = new GraphicsPath();

            // Create the outline for our custom end cap.
            const int arrowPartSize = 16;
            hPath.AddLine(new Point(0, 0), new Point(-arrowPartSize / 2, -arrowPartSize));
            hPath.AddLine(new Point(0, 0), new Point(arrowPartSize / 2, -arrowPartSize));

            CustomLineCap objCap = new CustomLineCap(null, hPath);

            // Set the start cap and end cap of the HookCap to be rounded.
            objCap.SetStrokeCaps(LineCap.Flat, LineCap.Flat);

            Pen outlinePen = new Pen(outlineColor);
            outlinePen.EndCap = LineCap.Custom;
            outlinePen.CustomEndCap = objCap;
            g.DrawPath(outlinePen, linePath);
        }

        public override void DrawFocused(Graphics g)
        {
            
        }

        public override void DrawSelected(Graphics g)
        {
            
        }

        public override bool IsThisSourceWidgetOK(UMLWidget widget)
        {
            return widget.Type == UMLWidgetType.CLASS;
        }

        public override bool IsThisDestinationWidgetOK(UMLWidget widget)
        {
            return widget.Type == UMLWidgetType.CLASS;
        }
    }
}
